//
//  NSString+DateFormat.m
//  Uang Pasti
//
//  Created by 李永彬 on 2025/8/15.
//

#import "NSString+DateFormat.h"

@implementation NSString (DateFormat)

- (NSDate * _Nullable )stringConvertToDate {
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"dd/MM/yyyy"];
    return [dateFormatter dateFromString: self];
}

- (NSString *)maskMiddleCharacters {
    if (self.length < 6) {
        return self;
    }
    
    NSMutableArray *characters = [NSMutableArray array];
    for (NSUInteger i = 0; i < self.length; i++) {
        [characters addObject:[self substringWithRange:NSMakeRange(i, 1)]];
    }
    
    for (NSUInteger i = 2; i < 6 && i < characters.count; i++) {
        characters[i] = @"*";
    }
    
    return [characters componentsJoinedByString:@""];
}

@end
